﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Reflection;

namespace Steve.UI
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited=true)]
    public sealed class ChildActionOrHttpPostAttribute : ActionMethodSelectorAttribute
    {
        private static readonly HttpPostAttribute _post = new HttpPostAttribute();

        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            if (controllerContext == null) throw new ArgumentNullException("controllerContext");

            if (_post.IsValidForRequest(controllerContext, methodInfo)) return true;
            if (controllerContext.IsChildAction) return true;

            return false;
        }
    }
}
